﻿@model List<Com.ProjectA.DAO.DAOPerson>
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}


@using (Html.BeginForm("SearchResult", "SearchPerson", FormMethod.Get))
{        
    <fieldset>
        <legend>Thông Tin Tìm kiếm Person</legend>
        @ViewData["A"]
        <table>
            <tr>
                <tr>
                    <td>
                        Person_Code :
                    </td>
                    <td>
                        @Html.TextBox("Person_code")
                    </td>
                    <td>
                        Họ :
                    </td>
                    <td>
                        @Html.TextBox("first_name")
                    </td>
                </tr>
                <tr>
                    <td>
                        Tên :
                    </td>
                    <td>
                        @Html.TextBox("last_name")
                    </td>
                    <td>
                        Lót :
                    </td>
                    <td>
                        @Html.TextBox("middle_name")
                    </td>
                </tr>
                <tr>
                    <td>
                        Ngày_sinh :
                    </td>
                    <td>
                        @Html.TextBox("birthday")
                    </td>
                    <td>
                        Ngày Mất :
                    </td>
                    <td>
                        @Html.TextBox("death_day")
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="submit" value="Search Person" />
                    </td>                    
                </tr>
        </table>
    </fieldset>
    if (Model != null)
    {
        <table class="grid">
            <tr>
                <th>
                    Per_SonCode
                </th>
                <th>
                    Họ
                </th>
                <th>
                    Lót
                </th>
                <th>
                    Tên
                </th>
                <th>
                    Ngày sinh
                </th>
                <th>
                    Ngày mất
                </th>
            </tr>
        
            @foreach (var item in Model)         
            {   
 
                <tr>
                    <td class="left"><a href="javascript:void(0);" class="btnPerson" id="@item.person_code">@item.person_code</a>
                    </td>
                    <td class="left">@item.first_name
                    </td>
                    <td class="left">@item.middle_name
                    </td>
                    <td class="left">@item.last_name
                    </td>
                    <td class="left">@item.birthday
                    </td>
                    <td class="left">@item.death_day
                    </td>
                    <td>
                    </td>
                </tr>
   
            }
           

        </table>
    <script language="javascript">
        $(document).ready(function () {
            var person1 = "";
            var person2 = "";
            $(".btnPerson").click(function () {
                if (person1 == "") {
                    person1 = $(this).attr("id");
                }
                else {
                    person2 = $(this).attr("id");
                }
                if (person1 != "" && person2 != "") {
                    $.ajax({
                        url: "PersonCall",
                        type: "POST",
                        data: "{A:'" + person1 + "',B:'" + person2 + "'}",
                        dataType: "json",
                        contentType: "application/json; charset=utf-8",
                        success: function (data) {
                            if (data.d != null) {
                                alert(data.d);
                                person1 = "";
                                person2 = "";
                            }
                        },
                        error: function () { }
                    });
                }
            });
        });
    </script>
    }
}
